package com.utils;

import java.io.Serializable;
import java.util.ArrayList;
import org.hibernate.Session;
import org.hibernate.Transaction;


public class TransacaoE2 {

    private Session s;
    private Transaction t;

    public TransacaoE2() {
        s = HibernateUtil.getSessionFactory().openSession();
        t = s.beginTransaction();
    }

    public void begin() {
        t.begin();
    }

    public void commit() {
        t.commit();
        s.close();
    }

    public void rollback() {
        t.rollback();
        s.close();
    }

    public void inserir(Serializable c) {
        s.save(c);
    }

    public void deletar(Serializable c) {
        s.delete(c);
    }

    public void alterar(Serializable c) {
        s.update(c);
    }

    public ArrayList mostrar(Class c, String filtro) {
        return (ArrayList) s.createQuery("Select w from " + c.getName() + " as w " + filtro).list();
    }


}
